import type { OrderDetailResult, OrderListParams, OrderListResult, OrderLogisticsResult, OrderParams, PreOrderResult } from "@/types/order"
import { http } from "@/utils/request"

//填写订单-获取预付订单
export const getMemberPreOrder = () => {
  return http<PreOrderResult>({
    url: '/member/order/pre',
    method: 'GET'
  })
}

//填写订单-获取立即购买订单
export const getMemberOrderNow = (data: {
  skuId: string
  count: string
  addressId?: string
}) => {
  return http<PreOrderResult>({
    url: '/member/order/pre/now',
    method: 'GET',
    data
  })
}

//提交订单
export const memberOrder = (data: OrderParams) => {
  return http<{ id: string }>({
    url: '/member/order',
    method: 'POST',
    data
  })
}

//获取订单详情
export const postOrderDetail = (id: string) => {
  return http<OrderDetailResult>({
    url: `/member/order/${id}`,
    method: 'GET'
  })
}

//模拟支付-内测版
export const payMock = (data: { orderId: string }) => {
  return http({
    url: '/pay/mock',
    method: 'GET',
    data
  })
}

//微信支付生产环境
export const payWxpay = (data: { orderId: string }) => {
  return http<WechatMiniprogram.RequestCommonPaymentOption>({
    url: '/pay/wxPay/miniPay',
    method: 'GET',
    data
  })
}

//模拟发货：仅在订单状态为待发货时，可模拟发货，调用后订单状态修改为待收货，包含模拟物流。
export const getOrderConsignment = (id: string) => {
  return http({
    url: `/member/order/consignment/${id}`,
    method: 'GET'
  })
}

//确认收货
export const confirmShop = (id: string) => {
  return http<OrderDetailResult>({
    url: `/member/order/${id}/receipt`,
    method: 'PUT'
  })
}


//填写订单-获取再次购买订单
export const getMemberOrderRepurchase = (id: string) => {
  return http<PreOrderResult>({
    url: `/member/order/repurchase/${id}`,
    method: 'GET'
  })
}

//获取订单物流
export const getOrderLogistics = (id: string) => {
  return http<OrderLogisticsResult>({
    url: `/member/order/${id}/logistics`,
    method: 'GET'
  })
}

//删除订单
export const deleteOrder = (data: { ids: string[] }) => {
  return http({
    url: '/member/order',
    method: 'DELETE',
    data
  })
}

//取消订单
export const cancelOrder = (id: string, data: { cancelReason: string }) => {
  return http<OrderDetailResult>({
    url: `/member/order/${id}/cancel`,
    method: 'PUT',
    data
  })
}

//获取订单列表
export const getMemberOrderList = (data: OrderListParams) => {
  return http<OrderListResult>({
    url: '/member/order',
    method: 'GET',
    data
  })
}